/**
 * 多种方式实现斐波拉契数列
 * 斐波拉契数列： fn(1) = 1 fn(2) = 1 fn(3) = 2
 */

 // 性能太差
const fiboracciSequence1 = (n) => {
    if (n === 1 || n === 2) {
        return 1
    }
    return fiboracciSequence1(n - 1) + fiboracciSequence1(n - 2)
}

const fiboracciSequence2 = (n, v1 = 1, v2 = 1) => {
    if (n === 1) return v1
    if (n === 2) return v2
    return fiboracciSequence2(n - 1, v2, v1 + v2)
}

console.time(fiboracciSequence2(1000))
console.log(fiboracciSequence2(1000))
console.timeEnd(fiboracciSequence2(1000))


